<html>
<head><meta charset="utf-8"><title>How to map HirId to user-written Id · t-compiler/help · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/index.html">t-compiler/help</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/How.20to.20map.20HirId.20to.20user-written.20Id.html">How to map HirId to user-written Id</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="223000339"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/How%20to%20map%20HirId%20to%20user-written%20Id/near/223000339" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> osa1 <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/How.20to.20map.20HirId.20to.20user-written.20Id.html#223000339">(Jan 16 2021 at 19:12)</a>:</h4>
<p>I have a HirId for a variable, how do I map it to the user-written variable? (a local variable, or parameter) Relatedly, I'm looking for places in the compiler where we raise a diagnostic line like "... defined here" where "..." is a user written variable.</p>



<a name="223001743"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/How%20to%20map%20HirId%20to%20user-written%20Id/near/223001743" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> bjorn3 <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/How.20to.20map.20HirId.20to.20user-written.20Id.html#223001743">(Jan 16 2021 at 19:38)</a>:</h4>
<p><code>tcx.map().get_entry(hir_id)</code>?</p>



<a name="223045279"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/How%20to%20map%20HirId%20to%20user-written%20Id/near/223045279" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Léo Lanteri Thauvin <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/How.20to.20map.20HirId.20to.20user-written.20Id.html#223045279">(Jan 17 2021 at 14:30)</a>:</h4>
<p>If you want the span of the variable, I'd expect something like:</p>
<div class="codehilite" data-code-language="Rust"><pre><span></span><code><span class="kd">let</span><span class="w"> </span><span class="n">span</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="k">match</span><span class="w"> </span><span class="n">tcx</span><span class="p">.</span><span class="n">hir</span><span class="p">().</span><span class="n">get</span><span class="p">(</span><span class="n">hir_id</span><span class="p">)</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="n">hir</span>::<span class="n">Node</span>::<span class="n">Local</span><span class="p">(</span><span class="n">local</span><span class="p">)</span><span class="w"> </span><span class="o">=&gt;</span><span class="w"> </span><span class="n">local</span><span class="p">.</span><span class="n">span</span><span class="p">,</span><span class="w"></span>
<span class="w">    </span><span class="n">hir</span>::<span class="n">Node</span>::<span class="n">Param</span><span class="p">(</span><span class="n">param</span><span class="p">)</span><span class="w"> </span><span class="o">=&gt;</span><span class="w"> </span><span class="n">param</span><span class="p">.</span><span class="n">span</span><span class="p">,</span><span class="w"></span>
<span class="w">    </span><span class="n">_</span><span class="w"> </span><span class="o">=&gt;</span><span class="w"> </span><span class="n">bug</span><span class="o">!</span><span class="p">(),</span><span class="w"></span>
<span class="p">};</span><span class="w"></span>
</code></pre></div>



<a name="223045485"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/How%20to%20map%20HirId%20to%20user-written%20Id/near/223045485" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> cjgillot <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/How.20to.20map.20HirId.20to.20user-written.20Id.html#223045485">(Jan 17 2021 at 14:35)</a>:</h4>
<p>If you only need the span, <code>tcx.hir().span(hir_id)</code> should do the trick.</p>



<a name="223071046"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/How%20to%20map%20HirId%20to%20user-written%20Id/near/223071046" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Noah Lev <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/How.20to.20map.20HirId.20to.20user-written.20Id.html#223071046">(Jan 18 2021 at 00:12)</a>:</h4>
<p>I think <span class="user-mention silent" data-user-id="119169">osa1</span> also wants the name of the variable.</p>



<a name="223083450"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/How%20to%20map%20HirId%20to%20user-written%20Id/near/223083450" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> osa1 <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/How.20to.20map.20HirId.20to.20user-written.20Id.html#223083450">(Jan 18 2021 at 05:56)</a>:</h4>
<p>Yeah I want the name (to be used in error messages), not the span.  I figured out how to do that yesterday but lost the code now...</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>